package com.adwin.addcoin.ui.main

import android.os.Bundle
import android.widget.RelativeLayout.LayoutParams
import com.adwin.addcoin.base.BaseFragment
import com.adwin.addcoin.base.BaseWebView
import com.adwin.addcoin.databinding.MainGameFragmentBinding

class GameFragment: BaseFragment<MainGameFragmentBinding, MainViewModel>(MainGameFragmentBinding::inflate,MainViewModel::class.java,false) {
    private var webview: BaseWebView? = null
//    private val webUrl = "http://test.adwin-win.com.s3-website-us-east-1.amazonaws.com/prizeClaw3/index.html"
    private val webUrl = "http://test.adwin-win.com.s3-website-us-east-1.amazonaws.com/home/index.html"
//    private val webUrl = "https://web.adwin-win.com/home/"
    override fun initFragment(binding: MainGameFragmentBinding, savedInstanceState: Bundle?) {
        webview = context?.let { BaseWebView(it.applicationContext) }
        webview?.initWeb()
        webview?.clearCache(true)
        webview?.loadUrl(webUrl)
        val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)
        webview?.layoutParams = layoutParams
        binding.clWebLayout.addView(webview)

    }

    override fun onBackPressed(): Boolean{
        return if (webview?.canGoBack() == true){
            webview?.goBack()
            false
        }else{
            true
        }
    }

    override fun onPause() {
        super.onPause()
        webview?.onPause()
    }

    override fun onResume() {
        super.onResume()
        webview?.onResume()
    }
}